import $ from 'jquery';
export function newFooter() {
  $(".footer-type-tab>li").click(function () {
    $(this).addClass("active").siblings().removeClass("active");
    $(".type-content-list").hide();
    $(".type-content-list").eq($(this).index()).css("display", "flex");
  })
  if ($(".footer-hd").length > 0 && $(".footer-hd-con").length == 0) {
    $(".footer-hd").wrapAll("<div class='footer-hd-con'></div>")
  }

  // 临时穿插首页访问埋点
  if ($("#openWinFocusNews").length > 0) {
    if (window.navigator.userAgent.indexOf('MSIE') > -1) {
      visit_3d66_page_index();
    } else {
    }
  }

  function getCookie(name) {
    var cookies = document.cookie.split("; ");
    for (var i = 0; i < cookies.length; i++) {
      var cookie = cookies[i].split("=");
      if (cookie[0] === name) {
        return cookie[1];
      }
    }
    return "";
  }
   
  function visit_3d66_page_index() {

    setTimeout(function () {

      try {

        var PLATFORM_TYPE = 2; //平台类型
        var PRODUCT_NAME = 0; //产品名称
        var UP_TIME = Math.floor(new Date().getTime() / 1000) || 0; //事件上报时间
        var USER_ID = 0; //用户ID
        var UID = getCookie("Hm_lvt_bh_ud") || 0; //游客ID
        var BROWSER = navigator.userAgent || ""; //浏览器信息
        var SCREEN_WIDTH = window.screen.width || 0; //屏幕宽度
        var SCREEN_HEIGHT = window.screen.height || 0; //屏幕高度
        var EXPERIMENTAL_GROUPING = 0; //实验组id
        var URL = window.location.href || ''; //页面地址
        var VIEW_URL = window.location.href || ''; //页面地址
        var TITLE = document.title || ''; //页面标题
        var REFER_URL = document.referrer || ''; //前向地址
        var RES_TYPE = $('#resType').val() || 0; //素材类型
        var SEARCH_WORD = 0; //搜索词
        var ACTIONID = $('#actionId').val() || 0;


        var USER_ID = 0;
        try {
          var userInfo = getCookie('userCookieData');
          if (!userInfo || userInfo === 'null') {
            USER_ID = 0;
          } else {
            var obj = JSON.parse(userInfo);
            USER_ID = obj.user_id;
          }
        } catch (error) {
          USER_ID = 0;
        }



        // 搜索词处理
        var new_search_word = '';
        if ($(".js-search-normal").val() != '') {
          new_search_word = $(".list-type-content").attr("category_filter_str") || $(".js-search-normal").val() || '';
        } else {
          new_search_word = $(".list-type-content").attr("category_word") || $(".js-search-normal").val() || '';
        }

        var basicAttributesArr = {
          platform_type: PLATFORM_TYPE,
          product_name: PRODUCT_NAME,
          up_time: UP_TIME,
          user_id: USER_ID,
          uid: UID,
          browser: BROWSER,
          screen_width: SCREEN_WIDTH,
          screen_height: SCREEN_HEIGHT,
          experimental_grouping: EXPERIMENTAL_GROUPING,
          url: URL,
          view_url: VIEW_URL,
          title: TITLE,
          refer_url: REFER_URL,
          res_type: $('#resType').val() || $('#res_type').val() || $('.search-keyword').attr('data-type') || 0,
          search_word: new_search_word || '',
          actionID: $('#actionId').val() || $(".list-type-content").attr("actionId") || '',
          category_filter_arr: [],
          buried_base_type: 'visit_3d66_page'
        }



        // 详情页、列表相关推荐高度AB测试 
        if ($('#details_relatedRecommendationsAb').length != 0) {
          if ($('#details_relatedRecommendationsAb').val() == '2') {
            basicAttributesArr.experimental_grouping = 'detail_recom_2';
          } else {
            basicAttributesArr.experimental_grouping = 'detail_recom_1';
          }
        }
        // 列表页切搜索接口埋点
        if ($(".list-type-content").length != 0) {
          basicAttributesArr.list_page_type = $(".list-type-content").attr("list_page_type") || ''; //列表页类型
          basicAttributesArr.list_filter_arr = $(".list-type-content").attr("list_filter_arr") || ''; //列表筛选参数
          basicAttributesArr.page = $(".list-type-content").attr("page_news") || ''; //页码
          basicAttributesArr.featured_category = $(".list-type-content").attr("featured_category") || ''; //特征词主词

          if ($(".list-type-content").attr("category_filter_arr")) {
            basicAttributesArr.category_filter_arr = $(".list-type-content").attr("category_filter_arr").split(",");
          } else {
            basicAttributesArr.category_filter_arr = '';
          }

        }


        $.ajax({
          url: 'https://tracking.3d66.com/tracking/v1/tracking/buried',
          type: 'post',
          data: basicAttributesArr,
          xhrFields: {
            withCredentials: true
          },
          success: function (res) {

          }
        })

      } catch (error) {
        console.log(error);
      }

    }, 500);

  }

  // 问答底部点击埋点
  $(".new-footer .new-footer-content a").click(function(){
    let _pathname = window.location.pathname;
    let containUrlArr = ['/news.html','/news/sucai','/news/s_','/sucai/','/news/','/map/sucai_','/answers/answers_','/answers/question_','answers_relation/relation_','/map/answers','/tiwen.html','/search/'];
    let flag = containUrlArr.filter(function(value) {
      return _pathname.indexOf(value) != -1;
    });//是否包含这些页面-问答和文章页面
    let seo_page = $("#seo_page").val();//二层保护 是否是seo页面
    if(flag.length && (seo_page || seo_page == 0) && typeof window.TP3D66SENSORSTRACK === 'function'){
      // let element_content = $.trim($(this).text());
      window.TP3D66SENSORSTRACK('LlbNewsClick',{
          click_site:3,
          // element_content:element_content
      });
    }
  })
}